<?php
require_once Path::getPath('users').'User.php';

define('USER_CURRENT', 'user');
/**
 * Description of UserManager
 *
 * @author josema
 */
class UserManager {
    static private $current_user = null;

    /**
     * Set in SESSION the current user
     * @param User $user
     */
    public function setCurrentUser(User $user){
        Session::init();
        $_SESSION[USER_CURRENT] = $user;
    }

    /**
     * Gets the current user from session
     * @return User
     */
    public function getCurrentUser(){
        Session::init();

        if(!self::$current_user){
            self::$current_user = $_SESSION[USER_CURRENT];

            // If we still not logged in, redirect to the login page
            if(!self::$current_user){
                header( "HTTP/1.1 301 Moved Permanently" );
                header( "Location: http://localhost/economy/rw/user/loginForm" );
                exit();
            }

        }

        return self::$current_user;
    }
}
?>
